﻿using B.S.DataBase.MyProject.Domain.BOM;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using MediatR;
using T.E.ERP.Read.API.Applicantions.Command.BomCOmmand;

namespace T.E.ERP.Read.API.Applicantions.CommandHandler.BomConnamdHandler
{
    public class GetReverBomCommandHandler:IRequestHandler<GetReverBomCommand,APIResult<List<BomInfo>>>
    {
        private readonly IBaseRepository<BomInfo> bomRep;
        public GetReverBomCommandHandler(IBaseRepository<BomInfo> bomRep)
        {
            this.bomRep = bomRep;
        }

        public Task<APIResult<List<BomInfo>>> Handle(GetReverBomCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<BomInfo>> result = new APIResult<List<BomInfo>>();
            var list = bomRep.GetAll().Result.Where(x => x.BomCode == request.BomCode);
            result.Code = APIEnum.成功;
            result.Msg = APIEnum.查询成功.ToString();
            result.data = list.ToList();
            return Task.FromResult(result);
        }
    }
}
